<?php

namespace App\Http\Requests;

use Illuminate\Validation\Rule;

/**
 * 参建单位 request验证类
 */
class PartCompanyRequest extends BaseRequest
{
    /**
     * 这个地方记得为 true, 默认为 false 会返回 403 未授权提示
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 验证规则
     * @return array
     */
    public function rules()
    {
        return [
            'title'      => 'required|between:2,127',
            'zerenzhe'   => 'required|between:2,127',
            'type'       => ['required', Rule::in([1,2,3])],
            'company_id' => 'required|exists:companies,id',
            'project_id' => 'required|exists:projects,id',
        ];
    }

    /**
     * 验证不通过提示
     * @return string[]
     */
    public function messages()
    {
        return [
            'title.required'      => '名称必填！',
            'title.between'       => '名称长度不合法！',
            'zerenzhe.required'   => '责任者必填！',
            'zerenzhe.between'    => '责任者长度不合法！',
            'type.required'       => '类型必填！',
            'type.in'             => '类型值不合法！',
            'company_id.required' => '公司id必填！',
            'company_id.exists'   => '公司不存在！',
            'project_id.required' => '项目id必填！',
            'project_id.exists'   => '项目不存在！',
        ];
    }

}
